﻿using Direct.IDAL.User.Jurisdiction;
using DirectSell.Model.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DirectSell.DAL.User.Jurisdiction
{
    public class ModifyInfoRespositoty:AbsRepository,IModifyInfoRespository
    {

        #region 初始化表名--郭文昊--2018年10月29日11:10:17
        public ModifyInfoRespositoty():base("UserInforMations")
        {

        }
        #endregion

        #region 查询该用户信息--郭文昊--2018年10月29日11:12:19
        /// <summary>
        /// 查询该用户信息
        /// </summary>
        /// <param name="UserCode">会员编号</param>
        /// <returns></returns>
        public async Task<UserInforMationDetails> GetInfo(string UserCode)
        {
            var sql = new StringBuilder().Append(" SELECT *  FROM UserInforMations ")
               .AppendFormat(" WHERE UserCode ='{0}'", UserCode);
            var model = await base.QueryAsync<UserInforMationDetails>(sql.ToString());
            return model.FirstOrDefault();
        }
        #endregion

        #region 修改资料--郭文昊--2018年10月29日11:13:59
        /// <summary>
        /// 修改资料 事务
        /// </summary>
        /// <param name="UserCode">会员编号</param>
        /// <returns></returns>
        public  bool ModifyInfo(UserInforMationDetails info)
        {
            var sql = new StringBuilder();
            sql.AppendFormat(" UPDATE UserInforMations SET ");
            sql.AppendFormat(" UserName='{0}', ",info.UserName);
            sql.AppendFormat(" IdNumber='{0}', ",info.IdNumber);
            sql.AppendFormat(" Phone='{0}', ", info.Phone);
            sql.AppendFormat(" BankName='{0}', ",info.BankName);
            sql.AppendFormat(" BankCode='{0}', ",info.BankCode);
            sql.AppendFormat(" CardHolder='{0}' ", info.CardHolder);
            sql.AppendFormat(" WHERE UserCode = '{0}' ",info.UserCode);
            return base.Execute(sql.ToString());
        }
        #endregion

        #region 判断二级密码--郭文昊--2018年10月30日14:54:05
        /// <summary>
        /// 判断二级密码
        /// </summary>
        /// <param name="UserCode">会员编号</param>
        /// <param name="SecondPassword">二级密码</param>
        /// <returns></returns>
        public async Task<bool> CheckSecondPassword(string UserCode,string SecondPassword)
        {
            var sql = new StringBuilder().Append(" SELECT COUNT(*)  FROM UserInforMations ")
               .AppendFormat(" WHERE UserCode ='{0}'  AND UserSecondPassWord='{1}'", UserCode, SecondPassword);
            long result = await base.QueryCount<long>(sql.ToString());
            return result > 0;
        }
        #endregion

    }
}
